package com.my.common.interception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.my.users.pojo.AUser;

/**
 *
 * @author mayue
 *
 */
@Component("userAuthInterception")
public class UserAuthInterception extends HandlerInterceptorAdapter
{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		HttpSession session = request.getSession();
		AUser user = (AUser) session.getAttribute("user");
		if(null != user){
			return true;
		}
		String info = "请先登陆";
		session.setAttribute("info", info);
		response.sendRedirect(request.getContextPath()+"/usersLogin.htm");
		return false;
	}

}
